home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was created & modified by George (ty) Tempel in
- connection with TopSoft, Inc. from Apple DTS source code:
-
- Apple Macintosh Developer Technical Support
-
- A collection of useful high-level File Manager routines.
-
- by Jim Luther, Apple Developer Technical Support
-
- from File: MoreFilesExtras.c
-
- Copyright © 1992-1994 Apple Computer, Inc.
- All rights reserved.
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABUFSSpecs.c
-
- NAME
- ABUFSSpecs.c, part of the ABox project source code,
- responsible for utility handling the AboutBox FSSpecs stuff.
-
- DESCRIPTION
- This file contains methods for the ABUFSSpecs class.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 15 july 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABUFSSpecs.h"
-
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
-
- /*========================= ABUFSSpecs::ABUFSSpecs =================================*/
- ABUFSSpecs::ABUFSSpecs (void)
- {
- // do nothing!
- } // end ABUFSSpecs
-
-
-
-
- /*========================= ABUFSSpecs::~ABUFSSpecs =================================*/
- ABUFSSpecs::~ABUFSSpecs (void)
- {
- // do nothing!
- } // end ~ABUFSSpecs
-
-
-
-
-
- /*========================= ABUFSSpecs::GetDirID =================================*/
- pascal OSErr
- ABUFSSpecs::GetDirID(short vRefNum,
- long dirID,
- StringPtr name,
- long *theDirID,
- Boolean *isDirectory)
- {
- CInfoPBRec pb;
- OSErr error;
-
- pb.hFileInfo.ioNamePtr = name;
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- pb.hFileInfo.ioFDirIndex = 0; // use ioNamePtr and ioDirID
- error = ::PBGetCatInfoSync(&pb);
- *theDirID = pb.hFileInfo.ioDirID;
- *isDirectory = (pb.hFileInfo.ioFlAttrib & 0x10) != 0;
- return (error);
- }
-
-
-
- /*========================= ABUFSSpecs::DirIDFromFSSpec =============================*/
-
- pascal OSErr
- ABUFSSpecs::DirIDFromFSSpec(const FSSpec *spec,
- long *theDirID,
- Boolean *isDirectory)
- {
- return (ABUFSSpecs::GetDirID(spec->vRefNum, spec->parID, (StringPtr)spec->name,
- theDirID, isDirectory));
- }
-
-
-
-
-
- /*========================= ABUFSSpecs::DetermineVRefNum ============================*/
-
- pascal OSErr
- ABUFSSpecs::DetermineVRefNum(StringPtr pathname,
- short vRefNum,
- short *realVRefNum)
- {
- HParamBlockRec pb;
- Str255 tempPathname;
- OSErr error;
-
- pb.volumeParam.ioVRefNum = vRefNum;
- if (pathname == nil)
- {
- pb.volumeParam.ioNamePtr = nil;
- pb.volumeParam.ioVolIndex = 0; // use ioVRefNum only
- } else {
- ::BlockMove ((Ptr)pathname, (Ptr)tempPathname, *pathname + 1);
- pb.volumeParam.ioNamePtr = (StringPtr)tempPathname; // use the copy so original isn't trashed
- pb.volumeParam.ioVolIndex = -1; // use ioNamePtr/ioVRefNum combination
- }
- error = ::PBHGetVInfoSync(&pb);
- if (realVRefNum)
- *realVRefNum = pb.volumeParam.ioVRefNum;
- return (error);
- }
-
-
-
-
-
- /*========================= ABUFSSpecs::GetDirItems ============================*/
-
- pascal OSErr
- ABUFSSpecs::GetDirItems(short vRefNum,
- long dirID,
- StringPtr name,
- Boolean getFiles,
- Boolean getDirectories,
- FSSpecPtr items,
- short reqItemCount,
- short *actItemCount,
- short *itemIndex) // start with 1, then use what's returned
- {
- CInfoPBRec pb;
- OSErr error = noErr;
- long theDirID;
- Boolean isDirectory;
- FSSpec *endItemsArray = items + reqItemCount;
-
- // NOTE: If I could be sure that the caller passed a real vRefNum and real directory
- // to this routine, I could rip out calls to DetermineVRefNum and GetDirID and this
- // routine would be much faster because of the overhead of DetermineVRefNum and
- // GetDirID and because GetDirID blows away the directory index hint the Macintosh
- // file system keeps for indexed calls. I can't be sure, so for maximum throughput,
- // pass a big array of FSSpecs so you can get the directory's contents with few calls
- // to this routine.
-
- // get the real volume reference number
- error = ABUFSSpecs::DetermineVRefNum(name, vRefNum, &pb.hFileInfo.ioVRefNum);
- if (error != noErr)
- return (error);
-
- // and the real directory ID of this directory (and make sure it IS a directory
- error = ABUFSSpecs::GetDirID(vRefNum, dirID, name, &theDirID, &isDirectory);
- if (error != noErr)
- return (error);
- else if (!isDirectory)
- return (dirNFErr);
-
-
- *actItemCount = 0;
- for (; (items < endItemsArray) && (error == noErr); )
- {
- pb.hFileInfo.ioNamePtr = (StringPtr) &items->name;
- pb.hFileInfo.ioDirID = theDirID;
- pb.hFileInfo.ioFDirIndex = *itemIndex;
- error = ::PBGetCatInfoSync(&pb);
- if (error == noErr)
- {
- items->parID = pb.hFileInfo.ioFlParID; // return item's parID
- items->vRefNum = pb.hFileInfo.ioVRefNum; // return item's vRefNum
- ++*itemIndex; // prepare to get next item in directory
-
- if (pb.hFileInfo.ioFlAttrib & 0x10) {
- if (getDirectories) {
- ++*actItemCount; // keep this item
- ++items; // point to next item
- }
- }
- else {
- if (getFiles) {
- ++*actItemCount; // keep this item
- ++items; // point to next item
- }
- }
- }
- }
- return (error);
- }
-
-
- // end of file.